<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Rule DSL Engine</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/heyui/themes/index.css"/>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="https://cdn.jsdelivr.net/npm/heyui"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!--    <link rel="stylesheet" href="css/lib/heyui.css" />-->
<!--    <script src="js/lib/vue.min.js"></script>-->
<!--    <script src="js/lib/heyui.js"></script>-->
<!--    <script src="js/lib/jquery.min.js"></script>-->
    <script src="js/lib/httpVueLoader.js"></script>
    <script src="js/common.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.0.2/dist/echarts.min.js"></script>
    <script src="https://pagecdn.io/lib/ace/1.4.12/ace.min.js" crossorigin="anonymous" integrity="sha256-T5QdmsCQO5z8tBAXMrCZ4f3RX8wVdiA0Fu17FGnU1vU=" ></script>
</head>
<body>
<div id="app">
    <h-loading v-if="loading" :loading="true"></h-loading>
    <Admin v-else-if="user"></Admin>
    <Login v-else></Login>
</div>
</body>
<script>
    // 提前加载大文件
    loadJs('echarts', 'ace', () => loadJs('ace-tools', 'ace-ext-searchbox', 'ace-lang-groovy'));
    // HeyUI.config({});
    let app = new Vue({
        el: '#app',
        data: {
            loading: true,
            // 当前登录用户信息
            user: null,
            // 用于各个组件临时数据传递
            tmp: {}
        },
        mounted: function () {
            this.getCurrentUser();
            ws({path: '/mnt/ws'})
        },
        methods: {
            getCurrentUser() {
                this.loading = true;
                $.ajax({
                    url: 'getCurrentUser',
                    success: (res) => {
                        this.loading = false;
                        if (res.code === '00') {
                            this.user = res.data;
                            if (this.user.permissions === undefined || this.user.permissions == null) this.user.permissions = []
                        } else this.$Message.error(res.desc)
                    },
                    error: (xhr) => {
                        this.loading = false
                        if (xhr.status !== 401) {
                            this.$Message.error(`${xhr.status} : ${xhr.responseText}`)
                        }
                    }
                })
            }
        }
    });
    window.app = app;

    // 设置全局自动关闭时间为5秒
    // app.$Notice.config({timeout: 5000});

    $.ajaxSetup({
        complete: (xhr) => {
            if (xhr.status == 401) { // 登录实效 or 未登录
                app.$data.user = null
            } else if (xhr.status == 403) {
                app.$Message.warn('没有权限');
            }
        }
    });
</script>
</html>